package cat.inkubator.plugin4j.xml;

import java.io.File;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.JAXBException;
/**
 *
 * @author gato
 */
@XmlRootElement
public class Configuration {
    
    private String urlPlugins;
    private String targetFolder;
    private File file;
        
    public String toXML() throws JAXBException{
        Xmlizer xml = new Xmlizer( Configuration.class );
        
        return xml.toXml(this);
    }
    
    public void fromXML( String xmlString ) throws JAXBException{
        Xmlizer xml =  new Xmlizer(Configuration.class);
        
        Configuration configuration = (Configuration) xml.fromXml(xmlString);
        
        this.urlPlugins = configuration.getUrlPlugins();
        this.targetFolder = configuration.getTargetFolder();
    }
    
    public boolean toFile( String fileName ){
        try{
            File file = new File(fileName);
            Xmlizer xml = new Xmlizer( Configuration.class );

            xml.xmlToFile(this, file);
        }catch( Exception e ){
            e.printStackTrace();
            return false;
        }
        
        return true;
    }

    public String getUrlPlugins() {
        return urlPlugins;
    }

    public void setUrlPlugins(String urlPlugins) {
        this.urlPlugins = urlPlugins;
    }

    public String getTargetFolder() {
        return targetFolder;
    }

    public void setTargetFolder(String targetFolder) {
        this.targetFolder = targetFolder;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

}
